package com.bdqn.t382.lx;

import java.lang.reflect.Method;

public class Lx03 {
    public static void main(String[] args) {
        try {
            Class<?> aClass = Class.forName("com.bdqn.t382.pojo.Person");
            Method getAge = aClass.getDeclaredMethod("getAge", null);
            getAge.setAccessible(true);
            Object returnAge = getAge.invoke(null, null);
            System.out.println("年龄是：" + returnAge);

            Method silentMethod = aClass.getDeclaredMethod("silentMethod", null);
            silentMethod.setAccessible(true);
            Object object = aClass.newInstance();
            silentMethod.invoke(object, null);

            Method setName = aClass.getDeclaredMethod("setName", String.class);
            setName.invoke(object, "New Person");
            Object returnName = aClass.getDeclaredMethod("getName").invoke(object);
            System.out.println("刚才设定的 name 是：" + returnName);

            Method getAddress = aClass.getDeclaredMethod("getAddress");
            Object returnAddress = getAddress.invoke(object, null);
            System.out.println(returnAddress);
        } catch (Exception e) {
          e.printStackTrace();
        }
    }
}
